import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsNotEmpty, IsNumber, Min } from 'class-validator';
import { DateDto, DiffDto, PageDto } from 'src/common/dto/dto';
import { Status } from 'src/dictionaries/index.enum';
import { FindOperator } from 'typeorm';

export class GetCategoryDto extends PageDto {
  /** 分类名称 */
  @ApiPropertyOptional({
    type: String,
    name: 'name',
    description: '分类名称',
  })
  public readonly name: FindOperator<string>;
  /** 是否启用 */
  @ApiPropertyOptional({
    name: 'status',
    description: '是否启用',
    enum: Status,
  })
  public readonly status: Status;
  /** 排序 */
  @ApiPropertyOptional({
    type: Number,
    name: 'sort',
    description: '排序',
  })
  public readonly sort?: number;
}
export class CreateCategoryDto extends DiffDto {
  /** 分类名称 */
  @IsNotEmpty({ message: '分类名称不能为空' })
  @ApiProperty({
    type: String,
    name: 'name',
    description: '分类名称',
  })
  public readonly name?: string;
  /** 语言 */
  @IsNotEmpty({ message: '语言不能为空' })
  @ApiProperty({
    type: String,
    name: 'lang',
    description: '语言',
  })
  public readonly lang?: string;
  /** 是否启用 */
  @IsEnum(Status)
  @IsNotEmpty({ message: '分类状态不能为空' })
  @ApiPropertyOptional({
    name: 'status',
    description: '是否启用',
    enum: Status,
  })
  public readonly status: Status;

  /** 排序 */
  @IsNotEmpty({ message: '排序不能为空' })
  @IsNumber()
  @Min(0, {
    message: '排序不能小于0'
  })
  @ApiProperty({
    type: Number,
    name: 'sort',
    description: '排序',
  })
  public readonly sort?: number;
}
export class UpdateCategoryDto extends CreateCategoryDto {
  @IsNotEmpty({ message: 'id不能为空' })
  @ApiProperty({
    type: Number,
    name: 'id',
    description: 'id',
  })
  public readonly id: number;
}
